var mSpeed : int = 50.0;
var rSpeed : int = 500.0;

static var view: changeView;
static var sCamera : int;

function Start()
{
	// set the variable view to the changeView script found on the GameObject Camera2D
	view = GameObject.Find("Camera2D").GetComponent(changeView);
	// set sCamera to that of the startCamera in the changeView Script
	sCamera = view.startCamera;
}

function Awake()
{
	// player's rotation is not affected by external factors
	// only unless "transform.rotate" is explicitly called.
	rigidbody.freezeRotation = true;
	
	// attach Character Controller to script
	var controller : CharacterController
	= GetComponent(CharacterController);
	if(!controller)
		gameObject.AddComponent("CharacterController");
}

// Use FixedUpdate rather than Update because of how Time.DeltaTime works
function FixedUpdate()
{
	var direction : Vector3;
	var rotation : float;
	
	// 2D Perspective
	if(sCamera == 1)
	{	
		// need to manually set the sCamera to that of the startCamera
		// for the character control to work correctly
		sCamera = view.startCamera;
		
		// Get input vector from keyboard
		direction
		= new Vector3(Input.GetAxis("Horizontal"), 0, 0);

	}
	
	// 3D Perspective
	if(sCamera == 2)
	{
		// need to manually set the sCamera to that of the startCamera
		// for the character control to work correctly
		sCamera = view.startCamera;
		
		// Get input vector from keyboardis.
		direction
		= new Vector3(Input.GetAxis("Vertical"), 0, -Input.GetAxis("Horizontal"));
		
		// transform object in direction by speed
		direction = transform.TransformDirection(direction);
//		direction *= mSpeed;
		
		
		
		// Rotation
		rotation = Input.GetAxis("Mouse X") * rSpeed;
		rotation *= Time.deltaTime;
		transform.Rotate(0, rotation, 0);
		
		var controller3d : CharacterController = GetComponent(CharacterController);
		var move3d = controller3d.Move(direction * mSpeed * Time.deltaTime);
	}
	
	// Move Controller
	var controller : CharacterController
	= GetComponent(CharacterController);
	
	// Move Player Object
	var move = controller.Move(direction * mSpeed * Time.deltaTime);
}